//
//  ViewController.m
//  CustomTbCellOptimizationObjC
//
//  Created by liy on 2024/10/9.
//

#import "ViewController.h"
#import "TableViewCell.h"
#import "MJExtension.h"

@interface ViewController ()

@property (strong, nonatomic) NSArray *statuses;

@end

@implementation ViewController

static NSString *ID = @"ViewController";

- (void)viewDidLoad {
	[super viewDidLoad];
	
	[self.tableView registerClass:[TableViewCell class] forCellReuseIdentifier:ID];
	self.tableView.estimatedRowHeight = 200;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	return self.statuses.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	NSLog(@"%s", __func__);
	TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
	cell.status = self.statuses[indexPath.row];
	
	return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
	NSLog(@"%s", __func__);
	
	Status *status = self.statuses[indexPath.row];
	return status.cellFrame.cellHeight;
}

/**懒加载 */
- (NSArray *)statuses {
	if (_statuses == nil) {
		_statuses = [Status mj_objectArrayWithFilename:@"statuses.plist"];
	}
	
	return _statuses;
}
@end
